package com.ruoyi.yey.student;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.yey.config.utils.PageUtil;
import com.ruoyi.yey.config.utils.PageVo;
import com.ruoyi.yey.config.utils.ResultUtil;
import com.ruoyi.yey.config.utils.ResultVo;
import com.ruoyi.yey.student.model.StudentSelectModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(tags = "学生管理")
@RequestMapping("/api/sys/student")
@RestController
public class StudentController {

    @Autowired
    private StudentService studentService;


    @ApiOperation("查询分页")
    @GetMapping("/findAllByPage")
    public Object findAllByPage(PageVo page, StudentEntity searchModel) {
        Page<Map> pageData = studentService.findAllByPage(PageUtil.initMpPage(page),searchModel);
        return pageData;
    }


    @ApiOperation("查询列表")
    @GetMapping("/findAllByList")
    public ResultVo getStudent(StudentEntity student) {
        List<Map> studentList = studentService.findAllByList(student);
        return ResultUtil.success(studentList);
    }

    @ApiOperation("根据班级id 查询学生列表")
    @GetMapping("/findAllByClassId/{classId}")
    public ResultVo findAllByClassId(@PathVariable int classId) {
        List<StudentSelectModel> studentList = studentService.findAllByClassId(classId);
        return ResultUtil.success(studentList);
    }

    @ApiOperation("根据学生姓名查询学生列表")
    @GetMapping("/findAllByStuName")
    public ResultVo findAllByClassId(String studentName) {
        List<StudentSelectModel> studentList = studentService.sysStudentFindBystuName(studentName);
        return ResultUtil.success(studentList);
    }



    @ApiOperation("添加")
    @PostMapping("/add")
    public void saveUser(@RequestBody @Validated StudentEntity student) {

        studentService.add(student);
    }

    @ApiOperation("根据id查询学生信息")
    @GetMapping("/findById/{id}")
    public StudentEntity findById(@PathVariable int id){
        StudentEntity studentEntity = studentService.findById(id);

        return studentEntity;
    }

    @ApiOperation("修改")
    @PostMapping("/edit")
    public void editKg(@RequestBody @Validated StudentEntity customAdmin) {
        studentService.edit(customAdmin);
    }


    @ApiOperation("删除")
    @DeleteMapping(value = "/delByIds/{ids}")
    public void delByIds(@PathVariable int ids) {

        studentService.delByIds(ids);
    }






}
